import hashlib
import time
import platform
import struct
import math

class RandByte(object):
    def __init__(self, bytes = 1, seed = ''):
        self.seed = seed
        self.index = 0
        self.bytes = bytes
    def _rand(self):
        s = str(time.time()) + hashlib.md5(self.seed).digest() + str(platform.processor())
        h = hashlib.sha1(s).digest()
        st = struct.unpack('20B', h)
        i = sum(st) % 256
        return struct.pack('B', i)
    def __iter__(self):
        return self
    def next(self):
        if self.bytes > self.index:
            r = self._rand()
            self.seed = r
            self.index += 1
            return r
        else:
            raise StopIteration

def _intrand(seed = ''):
    x = ''
    for i in RandByte(8, seed):
        x += i
    return struct.unpack('q', x)[0]

def randnum(min = None, max = None, seed = ''):
    x = _intrand(seed)
    if min and max:
        return min + (x % (max - min))
    if max:
        return x % max
    if min:
        return math.abs(x) + min
    return x

def enum(*sequential, **named):
    enums = dict(zip(sequential, range(len(sequential))), **named)
    return type('Enum', (), enums)

